/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgMallType
    {
        private readonly Dictionary<int, CfgMallType> _dataMap;
        private readonly List<CfgMallType> _dataList;

        /// <summary>
        /// OriginalType 和 Type 联合索引map(key1:OriginalType, Key2:Type, value:Id)
        /// </summary>
        public IReadOnlyDictionary<MallOriginalType, IReadOnlyDictionary<int, IReadOnlyList<int>>> MallFuncTypeMap { get; private set; }

        public TbCfgMallType(ByteBuf _buf)
        {
            //first read common data
            _TbCommonMallType _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonMallType(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgMallType>(size * 3 / 2);
            _dataList = new List<CfgMallType>(size);

            for (int i = 0; i < size; i++)
            {
                CfgMallType _v;
                _v = CfgMallType.DeserializeCfgMallType(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 
            { int __n0 = _buf.ReadSize(); var __f0 = new Dictionary<MallOriginalType, IReadOnlyDictionary<int, IReadOnlyList<int>>> (__n0 * 3 / 2); MallFuncTypeMap = __f0 ; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ) { MallOriginalType __k0; __k0 = (MallOriginalType)(_buf.ReadInt()); IReadOnlyDictionary<int, IReadOnlyList<int>> __v0; { int __n1 = _buf.ReadSize(); var __f1 = new Dictionary<int, IReadOnlyList<int>> (__n1 * 3 / 2); __v0 = __f1 ; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ) { int __k1; __k1 = _buf.ReadInt(); IReadOnlyList<int> __v1; { int __n2 = _buf.ReadSize(); var __f2 = new int[__n2]; __v1 = __f2; for (var __i2 = 0 ; __i2 < __n2 ; __i2++ ){ int __v2; __v2 = _buf.ReadInt(); __f2[__i2] = __v2;} } __f1.Add(__k1, __v1); } } __f0.Add(__k0, __v0); } }

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgMallType> DataMap => _dataMap;
        public IReadOnlyList<CfgMallType> DataList => _dataList;

        public CfgMallType Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgMallType] config not found,id:" + key.ToString());

            return null;
        }

        public CfgMallType GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "malltype";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgMallType LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgMallType(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgMallType
    {
        private CfgMallType(ByteBuf _buf, _TbCommonMallType _commonData)
        {
            Id = _buf.ReadInt();
            OriginalType = (MallOriginalType)(_buf.ReadInt());
            Type = _buf.ReadInt();
            TabName = TableCenter.GetI18NText(_buf.ReadInt());
            ShowType = (MallShowType)(_buf.ReadInt());
            TimeLimitType = (MallType_TimeLimitType)(_buf.ReadInt());
            { int dataIndex = _buf.ReadInt() - 1; TimeLimitOpen = _commonData._field0[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; TimeLimitEnd = _commonData._field1[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; Icon = _commonData._field2[dataIndex]; }
            Source = _buf.ReadInt();
            MallLinkageMallGoods = _buf.ReadInt();
            AutoBuyPanel = _buf.ReadBool();
            { int dataIndex = _buf.ReadInt() - 1; BG = _commonData._field3[dataIndex]; }

            PostInit();
        }

        internal static CfgMallType DeserializeCfgMallType(ByteBuf _buf, _TbCommonMallType _commonData)
        {
            return new CfgMallType(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 所属入口（1.默认商城，2.活动商城，按需求逐步新增）
        /// </summary>
        public MallOriginalType OriginalType { get; private set; }
        /// <summary>
        /// 商城大类型 1-推荐 2-月卡 3-充值 4-商城 5-隐藏兑换 6-商店 7-家园 8-时装 9-兑换商店，其他用 OriginalType+数字组合
        /// </summary>
        public int Type { get; private set; }
        /// <summary>
        /// 二级页签名字
        /// </summary>
        public string TabName { get; private set; }
        /// <summary>
        /// 显示类型 0-根据主类型Type 1-普通 2-长条
        /// </summary>
        public MallShowType ShowType { get; private set; }
        /// <summary>
        /// 限时模式(1-时间点)
        /// </summary>
        public MallType_TimeLimitType TimeLimitType { get; private set; }
        /// <summary>
        /// 开启时间
        /// </summary>
        public string TimeLimitOpen { get; private set; }
        /// <summary>
        /// 结束时间
        /// </summary>
        public string TimeLimitEnd { get; private set; }
        /// <summary>
        /// 一级页签图标
        /// </summary>
        public string Icon { get; private set; }
        /// <summary>
        /// 前往跳转
        /// </summary>
        public int Source { get; private set; }
        /// <summary>
        /// 关联商品
        /// </summary>
        public int MallLinkageMallGoods { get; private set; }
        /// <summary>
        /// 是否自动打开购买
        /// </summary>
        public bool AutoBuyPanel { get; private set; }
        /// <summary>
        /// 背景资源/充值与时装使用
        /// </summary>
        public string BG { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonMallType
    {

        internal IReadOnlyList<string> _field0 { get; private set; }
        internal IReadOnlyList<string> _field1 { get; private set; }
        internal IReadOnlyList<string> _field2 { get; private set; }
        internal IReadOnlyList<string> _field3 { get; private set; }
        internal _TbCommonMallType(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field2 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field3 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
        }

    }
}
